home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / SOURCE.BIN / RadioBox.java < prev    next >
Encoding:
Java Source  |  1997-06-19  |  7.7 KB  |  232 lines

  1. /*
  2.  *
  3. */
  4.  
  5. package symantec.itools.db.awt;
  6.  
  7. import java.util.*;
  8. import symjava.sql.*;
  9. import java.lang.*;
  10. import symantec.itools.db.net.*;
  11. import symantec.itools.db.pro.*;
  12.  
  13. public class RadioBox extends java.awt.CheckboxGroup implements ProjLink
  14. {
  15.     /**
  16.      * The ProjBinder object which this component can use to get data from
  17.      * the server, or change data at the database server.
  18.      */
  19.     private ProjBinder m_ProjBinder;
  20.  
  21.     private RelationView m_relView;
  22.     private String       m_projection;
  23.     private int          m_treatBlankAs = 0;
  24.     private boolean m_DynamicUpdate = false;
  25.  
  26.     private Vector rbkVector = new Vector();
  27.     private java.awt.Container m_Container;
  28.  
  29.     /**
  30.      * Constructs a new TextField.
  31.      */
  32.     public RadioBox(java.awt.Container c)
  33.     {
  34.         super();
  35.         m_Container = c;
  36.     }
  37.  
  38.     /**
  39.      * Implement the ProjLink interface function, init().
  40.      * This function is called when the control is first bound to data.
  41.      *
  42.      * @param binder The ProjBinder binder object which this component can use
  43.      *               to change data at the database server.
  44.      */
  45.     public void init (ProjBinder binder)
  46.     {
  47.         m_ProjBinder = binder;
  48.  
  49.     }
  50.  
  51.     public RelationView getRelView()
  52.     {
  53.         return m_relView;
  54.     }
  55.  
  56.     public String getProjection()
  57.     {
  58.         return m_projection;
  59.     }
  60.  
  61.     public void setTreatBlankAs(String blank)
  62.     {
  63.         if (new String(blank).toUpperCase().equals("DEFAULT"))
  64.         {
  65.             m_treatBlankAs = RelationView.SETBLANKTODEFAULT;
  66.         }
  67.         else if (new String(blank).toUpperCase().equals("NULL"))
  68.             {
  69.                 m_treatBlankAs = RelationView.SETBLANKTONULL;
  70.             }
  71.             else if (new String(blank).toUpperCase().equals("BLANK"))
  72.             {
  73.                 m_treatBlankAs = RelationView.SETBLANKTOEMPTY;
  74.             }
  75.     }
  76.  
  77.     public void setBinding(RelationView relView, String projection)
  78.     {
  79.         m_relView = relView;
  80.         m_projection = projection;
  81.         try
  82.         {
  83.             int projectionNumber = relView.findProjByName(projection);
  84.             relView.bindProj(projectionNumber, this);
  85.         }
  86.         catch (SQLException Ex)
  87.         {
  88.             raiseException(
  89.                 "SQLException from RadioBox.setBinding: "
  90.                 + Ex.getMessage());
  91.         }
  92.     }
  93.  
  94.     void addCheckboxes(java.awt.Container c)
  95.     {
  96.         int compCnt = c.countComponents();
  97.         java.awt.Component[] compArray = new java.awt.Component[compCnt];
  98.         compArray = c.getComponents();
  99.         for (int loops = 0; loops < compArray.length; loops++)
  100.         {
  101.             if (compArray[loops] instanceof java.awt.Checkbox)
  102.             {
  103.                 if (this.equals(((java.awt.Checkbox)compArray[loops]).getCheckboxGroup()))
  104.                 {
  105.                     rbkVector.addElement(compArray[loops]);
  106.                 }
  107.             }
  108.         }
  109.     }
  110.  
  111.     /**
  112.      * Implement the ProjLink interface function, notifyDataChange().
  113.      * This function is called when the projection's data changes at the database.
  114.      *
  115.      * @param binder The ProjBinder binder object which this component can use
  116.      *               to get or change data at the database server.
  117.      */
  118.     public void notifyDataChange(ProjBinder binder)
  119.     {
  120.         int rbCurrent = 0;
  121.         boolean itemfound = false;
  122.  
  123.         addCheckboxes(m_Container);
  124.  
  125.         try
  126.         {
  127.             while (rbCurrent < rbkVector.size())
  128.             {
  129.                 symantec.itools.db.awt.RadioButton rb = (symantec.itools.db.awt.RadioButton)rbkVector.elementAt(rbCurrent);
  130.                 if (rb != null)
  131.                 {
  132.                     if (rb.getLabel().equals(binder.getStringValue()))
  133.                     {
  134.                         itemfound = true;
  135.                         break;
  136.                     }
  137.                     else
  138.                     {
  139.                         rbCurrent++;
  140.                     }
  141.                 }
  142.             }
  143.         }
  144.         catch (SQLException Ex)
  145.         {
  146.             raiseException(
  147.                 "SQLException from RadioBox.notifyDataChange: "
  148.                 + Ex.getMessage());
  149.         }
  150.         catch (java.io.IOException Ex)
  151.         {
  152.             raiseException(
  153.                 "IOException from RadioBox.notifyDataChange: "
  154.                 + Ex.getMessage());
  155.         }
  156.         if (!itemfound)
  157.         {
  158.         setCurrent(null);
  159.         }
  160.     }
  161.  
  162.     public boolean notifySetData(ProjBinder binder) throws SQLException
  163.     {
  164.         return ( notifyStateChange() );
  165.     }
  166.  
  167.     boolean notifyStateChange()
  168.     {
  169.         if (getCurrent() == null)
  170.         {
  171.             try
  172.             {
  173.                 if (m_ProjBinder != null && m_ProjBinder.isWritable())
  174.                 {
  175.                     m_ProjBinder.setValueFromString("", 0, m_treatBlankAs);
  176.                 }
  177.             }
  178.             catch (SQLException Ex)
  179.             {
  180.                 raiseException(
  181.                     "SQLException from RadioBox.notifyStateChange: "
  182.                     + Ex.getMessage());
  183.                 return false;
  184.             }
  185.             catch (java.io.IOException Ex)
  186.             {
  187.                 raiseException(
  188.                     "IOException from RadioBox.notifyStateChange: "
  189.                     + Ex.getMessage());
  190.                 return false;
  191.             }        }
  192.         return true;
  193.     }
  194.  
  195.     //*************************************************************************//
  196.     //                                                                         //
  197.     // FUNCTION: raiseException                                                //
  198.     //                                                                         //
  199.     //  PURPOSE:                                                               //
  200.     //                                                                         //
  201.     //  PARAMETERS:                                                            //
  202.     //                                                                         //
  203.     //  RETURNS:                                                               //
  204.     //                                                                         //
  205.     // COMMENTS:                                                               //
  206.     //                                                                         //
  207.     //*************************************************************************//
  208.  
  209.     void raiseException(String text)
  210.     {
  211.         System.out.println(text);
  212.     }
  213.  
  214.     //*************************************************************************//
  215.     //                                                                         //
  216.     // FUNCTION: setDynamicUpdate                                              //
  217.     //                                                                         //
  218.     //  PURPOSE:                                                               //
  219.     //                                                                         //
  220.     // PARAMETERS:                                                             //
  221.     //                                                                         //
  222.     //  RETURNS:                                                               //
  223.     //                                                                         //
  224.     // COMMENTS:                                                               //
  225.     //                                                                         //
  226.     //*************************************************************************//
  227.  
  228.     public void setDynamicUpdate(boolean update)
  229.     {
  230.         m_DynamicUpdate = update;
  231.     }
  232. }